/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.blitzcoder.collide;

import de.blitzcoder.collide.icons.Icon;
import de.blitzcoder.collide.util.Log;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JToolBar;

/**
 *
 * @author blitzcoder
 */
public class ActionToolBar extends JToolBar {
    
    // Actions
    public static JButton      actionNewFile;                  // New
    public static JButton      actionOpenFile;                 // Open
    public static JButton      actionSaveFile;                 // Save
    public static JButton      actionShiftLeft;                // ShiftLeft
    public static JButton      actionShiftRight;               // ShiftRight
    public static JButton      actionUndo;                     // Undo
    public static JButton      actionRedo;                     // Redo
    public static JButton      actionCopy;                     // Copy
    public static JButton      actionCut;                      // Cut
    public static JButton      actionDelete;                   // Delete
    public static JButton      actionPaste;                    // Paste
    public static JButton      actionSelectAll;                // SelectAll
    public static JButton      actionCompileAndRun;            // Compile and Run
    public static JButton      actionCompile;                  // Just Compile
    public static JButton      actionStatus;                   // Display the status
    public static ImageIcon    actionStatusStopped;            // Stopped Icon
    public static ImageIcon    actionStatusRunning;            // Running Icon
    public static JCheckBox    actionBuildGuiApp;              // Checkbox for building GUI-App
    public static JCheckBox    actionBuildDebug;               // Checkbox for building Debug
    public static JCheckBox    actionBuildQuick;               // Checkbox for building quick
    public static JComboBox    actionSelectBuildFile;          // Combobox to select file to build
    
    public ActionToolBar() {
        super();
        Log.log("Creating Toolbar");
        setFloatable(false);
        setRollover(true);
        createButtons();
        addActions();
    }

    private void addActions() {
        // The ActionListener
        actionNewFile.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MenuWorker.createNewFile();
            }
        });
        actionOpenFile.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MenuWorker.openDialog();
            }
        });
        actionSaveFile.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MenuWorker.saveFile();
            }
        });
        actionShiftLeft.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MenuWorker.shiftLeft();
            }
        });
        actionShiftRight.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MenuWorker.shiftRight();
            }
        });
        actionCompileAndRun.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e) {
                MenuWorker.compileAndRun();
            }
        });
        actionCompile.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e) {
                MenuWorker.compile();
            }
        });
        actionCopy.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MenuWorker.copy();
            }
        });
        actionCut.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MenuWorker.cut();
            }
        });
        actionDelete.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MenuWorker.delete();
            }
        });
        actionPaste.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MenuWorker.paste();
            }
        });
        actionRedo.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MenuWorker.redo();
            }
        });
        actionSelectAll.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MenuWorker.selectAll();
            }
        });
        actionUndo.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                MenuWorker.undo();
            }
        });
    }
    
    private void createButtons() {
        // Create the Buttons
        actionNewFile = new JButton();
        actionOpenFile = new JButton();
        actionSaveFile = new JButton();
        actionShiftLeft = new JButton();
        actionShiftRight = new JButton();
        actionCompileAndRun = new JButton();
        actionCompile   = new JButton();
        actionStatus = new JButton();
        actionCopy = new JButton();
        actionCut = new JButton();
        actionDelete = new JButton();
        actionPaste = new JButton();
        actionRedo = new JButton();
        actionSelectAll = new JButton();
        actionUndo = new JButton();
        actionBuildGuiApp = new JCheckBox("GUI Build");
        actionBuildQuick = new JCheckBox("Quick Build");
        actionBuildDebug = new JCheckBox("Debug Build");
        actionSelectBuildFile = new JComboBox(new String[] { "Aktuelle Datei" } );
        
        
        //  Not paint the borders
        actionNewFile.setBorderPainted(false);
        actionOpenFile.setBorderPainted(false);
        actionSaveFile.setBorderPainted(false);
        actionShiftLeft.setBorderPainted(false);
        actionShiftRight.setBorderPainted(false);
        actionCompileAndRun.setBorderPainted(false);
        actionCompile.setBorderPainted(false);
        actionStatus.setBorderPainted(false);
        actionCopy.setBorderPainted(false);
        actionCut.setBorderPainted(false);
        actionDelete.setBorderPainted(false);
        actionPaste.setBorderPainted(false);
        actionRedo.setBorderPainted(false);
        actionSelectAll.setBorderPainted(false);
        actionUndo.setBorderPainted(false);
        
        // Set start states of the checkboxes
        actionBuildGuiApp.setSelected(true);
        actionBuildQuick.setSelected(true);
        actionBuildDebug.setSelected(true);
        
        actionNewFile.setToolTipText("Neue Datei erstellen");
        actionOpenFile.setToolTipText("Öffnen");
        actionSaveFile.setToolTipText("Speichern");
        actionCompileAndRun.setToolTipText("Kompilieren und Ausführen");
        actionShiftLeft.setToolTipText("Nach links einrücken");
        actionShiftRight.setToolTipText("Nach rechts einrücken");
        actionCompile.setToolTipText("Kompilieren");
        actionStatus.setToolTipText("Status");
        actionCopy.setToolTipText("Kopieren");
        actionCut.setToolTipText("Ausschneiden");
        actionDelete.setToolTipText("Löschen");
        actionPaste.setToolTipText("Einfügen");
        actionRedo.setToolTipText("Wiederholen");
        actionSelectAll.setToolTipText("Alles markieren");
        actionUndo.setToolTipText("Rückgängig");
        actionSelectBuildFile.setToolTipText("Den zu kompilierenden Code auswählen");
        
        // add the icons
        try {
            actionNewFile.setIcon(Icon.load("new.png"));
            actionOpenFile.setIcon(Icon.load("open.png"));
            actionSaveFile.setIcon( Icon.load("save.png"));
            actionShiftLeft.setIcon( Icon.load("indent-less.png") );
            actionShiftRight.setIcon( Icon.load("indent-more.png") );
            actionCompileAndRun.setIcon( Icon.load("buildandrun.png"));
            actionCompile.setIcon( Icon.load("build.png"));
            actionStatusStopped =  Icon.load("stopped.png");
            actionStatusRunning =  Icon.load("running.png");
            actionCopy.setIcon(Icon.load("copy.png"));
            actionCut.setIcon(Icon.load("cut.png"));
            actionDelete.setIcon(Icon.load("delete.png"));
            actionPaste.setIcon(Icon.load("paste.png"));
            actionRedo.setIcon(Icon.load("redo.png"));
            actionSelectAll.setIcon(Icon.load("selectall.png"));
            actionUndo.setIcon(Icon.load("undo.png"));
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        
        // Add the Buttons
        
        add(actionNewFile);
        add(actionOpenFile);
        add(actionSaveFile);
        add(new JToolBar.Separator());
        add(actionUndo);
        add(actionRedo);
        add(actionCopy);
        add(new JToolBar.Separator());
        add(actionShiftLeft);
        add(actionShiftRight);
        add(new JToolBar.Separator());
        add(actionCut);
        add(actionPaste);
        add(actionDelete);
        add(actionSelectAll);
        add(new JToolBar.Separator());
        add(actionCompile);
        add(actionCompileAndRun);
        add(actionStatus);
        add( new JToolBar.Separator());
        
        JPanel pa = new JPanel();
        pa.setLayout(new GridLayout(2,2));
        pa.add(actionBuildDebug);
        pa.add(actionBuildQuick);
        pa.add(actionBuildGuiApp);
        pa.add(actionSelectBuildFile);
        add(pa);
        
    }
    
}
